package util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexHelper {
	
	public static final String ID_REGEX = "[1-9]{1}[0-9]{0,}\\s";
	public static final String NAME_REGEX = "[a-zA-Z]+\\s";
	public static final String EMAIL_REGEX = "\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*\\s";
	public static final String SEX_REGEX = "(true|false)\\s";
//	public static final String BIRTHDAY_REGEX = "([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))";
	public static final String BIRTHDAY_REGEX = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
	
	public static boolean isLegal(String regex, String target) {

		target=ID_REGEX+NAME_REGEX+EMAIL_REGEX+SEX_REGEX;
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(target);
		while (matcher.find()) {
			System.out.println("legal");
			return true;
		}
		return false;

	}
	
	public static void main(String[] args) {
		String s="8 john john@163.com true			 1999-10-2";
//		8 john john@163.com true			 1999-10-2
//		2 tommy tom@163.com 		true 2000/9-3
//		5 alice alic2@qq.com 		false 1999-10-23
//		1 nina     johndfm	 true 1999-10-2
//		4 tom tom@163.com true 2000-9-3
//		3 mike alic2@qq.com fals 1999-10-23
		
		isLegal(ID_REGEX+NAME_REGEX+EMAIL_REGEX+SEX_REGEX, s);
	}

}
